import pro from './pro.proxy.ts'
import dev from './dev.proxy.ts'

import type { baseURL } from './proxy.type.ts'

class ServerConfig {
  static httpUrl: Record<string, baseURL> = {
    development: dev.baseUrl,
    production: pro.baseUrl,
  }
  static proxy = {
    development: dev.proxy,
    production: pro.proxy,
  }
}

class InitServeConfig {
  _env: string = 'development'

  getProxy(env: string) {
    // console.log('env', env)
    this._env = env
    const isEnvKey = (key: string): key is keyof typeof ServerConfig.proxy => {
      return ['development', 'production'].includes(key)
    }
    if (env && isEnvKey(env)) {
      return ServerConfig.proxy[env]
    }
    return ServerConfig.proxy.development
  }

  getEnv() {
    return this._env
  }

  getHttpUrl() {
    return ServerConfig.httpUrl
  }
}

export default new InitServeConfig()
